import request from '@/config/axios'
import type { Dayjs } from 'dayjs'

/** 维修申请信息 */
export interface RepairRequest {
  id: number // id
  repairNo?: string // 申请单号
  faultId?: number // 故障分类id
  equipmentId?: number // 设备id
  equipmentName?: string // 设备名称
  faultTime?: string | Dayjs // 故障发生时间
  requestUserId?: number // 申请人ID
  requestUserName?: number // 申请人
  urgency?: number // 紧急程度
  description?: string // 故障描述
  repairWay?: number // 维修方式
  dutyUserId?: string // 维修人ID
  dutyUserName: string // 维修人名称
  status: number // 状态
  resolved: number // 是否解决
  expectedResolveTime: string | Dayjs // 期望解决日期
}

// 维修申请 API
export const RepairRequestApi = {
  // 查询维修申请分页
  getRepairRequestPage: async (params: any) => {
    return await request.get({ url: `/business/repair-request/page`, params })
  },

  // 查询维修任务分页
  getRepairRequestTaskPage: async (params: any) => {
    return await request.get({ url: `/business/repair-request/taskPage`, params })
  },

  // 查询维修申请详情
  getRepairRequest: async (id: number) => {
    return await request.get({ url: `/business/repair-request/get?id=` + id })
  },

  // 新增维修申请
  createRepairRequest: async (data: RepairRequest) => {
    return await request.post({ url: `/business/repair-request/create`, data })
  },

  // 修改维修申请
  updateRepairRequest: async (data: RepairRequest) => {
    return await request.put({ url: `/business/repair-request/update`, data })
  },

  // 删除维修申请
  deleteRepairRequest: async (id: number) => {
    return await request.delete({ url: `/business/repair-request/delete?id=` + id })
  },

  /** 批量删除维修申请 */
  deleteRepairRequestList: async (ids: number[]) => {
    return await request.delete({
      url: `/business/repair-request/delete-list?ids=${ids.join(',')}`
    })
  },

  // 导出维修申请 Excel
  exportRepairRequest: async (params) => {
    return await request.download({ url: `/business/repair-request/export-excel`, params })
  }
}
